package ro.dta.idbi.interfaces.sql;

import java.awt.Point;
import java.util.List;

import com.mxgraph.view.mxGraph;

/**
 * Interface for SQL table constructs
 * 
 * @author Tudor Dobrila
 * 
 */
public interface ISqlTable extends ISqlConstruct {

	/**
	 * @param position
	 *            the position to set
	 */
	void setPosition(Point position);

	/**
	 * @return the position
	 */
	Point getPosition();

	/**
	 * Check if a column with the given name exists
	 * 
	 * @param name
	 *            Name of the column
	 * @return True if a column with this name exists, false otherwise
	 */
	boolean columnNameExists(String name);

	/**
	 * Add a column
	 * 
	 * @param column
	 *            Column to add to the table
	 */
	void addColumn(ISqlColumn column);

	/**
	 * Add a column
	 * 
	 * @param value
	 *            Value displayed in the column
	 * @param style
	 *            Style of the column
	 * @return Newly created column object
	 */
	ISqlColumn addColumn(String value, String style);

	/**
	 * Add a column newColumn before column
	 */
	void addBeforeColumn(ISqlColumn column, ISqlColumn newColumn);

	/**
	 * Add a column with a given value and style before another column
	 */
	void addBeforeColumn(ISqlColumn column, String value, String style);

	/**
	 * Remove a column from the table
	 * 
	 * @param column
	 *            Column to remove
	 */
	boolean removeColumn(ISqlColumn column);

	/**
	 * Get the column with the given name
	 * 
	 * @return Column with the given name, null if no such column exists
	 */
	ISqlColumn getColumn(String name);

	/**
	 * @return Columns of this table
	 */
	List<ISqlColumn> getColumns();

	/**
	 * Add the current cell and all of its children to a graph
	 * 
	 * @param graph
	 *            Graph that will hold this cell and its children
	 */
	void layout(mxGraph graph);

	/**
	 * Recalculate positions for all child columns
	 * 
	 * @param graph
	 *            Graph where the table will be drawn
	 */
	void relayout(mxGraph graph);

	/**
	 * Get the names of the supertypes of the table
	 * 
	 * @return Name of the supertypes of the table
	 */
	List<String> getSupertypesNames();

	/**
	 * Add a table as the supertype of the current table
	 * 
	 * @param table
	 *            Table to add as supertype
	 */
	void addSupertype(ISqlTable table);

	/**
	 * Get the names of the supertypes of the table
	 * 
	 * @return Name of the supertypes of the table
	 */
	List<ISqlTable> getSupertypes();

	/**
	 * Add a foreign key constraint to the table
	 * 
	 * @param foreignKey
	 *            Foreign key constraint to add
	 */
	void addForeignKey(ISqlForeignKey foreignKey);

	/**
	 * Get the foreign key constraints in the table
	 * 
	 * @return Foreign key constraints in the table
	 */
	List<ISqlForeignKey> getForeignKeys();

	/**
	 * Get the columns in the primary key constraint of the table
	 * 
	 * @return The columns in the PK constraint of the table
	 */
	List<ISqlColumn> getPrimaryKey();

	/**
	 * Add a child of this table
	 * 
	 * @param o1
	 *            Table to add as a child of this table
	 */
	void addChild(ISqlTable o1);

	/**
	 * Get the child tables of this table
	 * 
	 * @return Child tables of this table
	 */
	List<ISqlTable> getChildren();

	/**
	 * Get the IQL query used to retrieve all contents of the table
	 * 
	 * @return IQL query used to retrieve all contents of the table
	 */
	String getIqlQuery();

}